#ifndef __GAMELAYER_H__
#define __GAMELAYER_H__

//#define GOAL_WIDTH 400

#include "cocos2d.h"
#include "GameSprite.h"

using namespace cocos2d;

class GameLayer : public cocos2d::CCLayer
{
	CCArray * _pieces;
	CCSprite * _mainPic;
	CCLabelTTF * _timeLeftLabel;
	CCLabelTTF * _playerScoreLabel;
	CCLabelTTF * _moveCountLabel;
	CCSize _screenSize;
	int _playerScore;
	int _pieceNum;
	int _movedIndex;
	enum WIN_STATE {PLAYING, WIN, LOSE} _gameState; // 0: not yet, 1: win, -1: lose
	float _timeLeft;
	int _moveCount;
	int _row;
	int _column;
	float _pieceWidth;
	float _pieceHeight;

	//void playerScore (int player);
public:
	//CC_SYNTHESIZE(CCInteger, _pieceNum, PieceNum);

	~GameLayer();
    // Here's a difference. Method 'init' in cocos2d-x returns bool, instead of returning 'id' in cocos2d-iphone
    virtual bool init();  

    // there's no 'id' in cpp, so we recommand to return the exactly class pointer
    static cocos2d::CCScene* scene();
    
    void setPieceNum(int num);

    virtual void ccTouchesBegan(CCSet* pTouches, CCEvent* event);
    virtual void ccTouchesMoved(CCSet* pTouches, CCEvent* event);
    virtual void ccTouchesEnded(CCSet* pTouches, CCEvent* event);
    void update (float dt);

    int calcIndexFromPos(CCPoint pos);
    CCPoint calcPosFromIndex(int index);

    bool isWin();
    bool isAdjacent(int index1, int index2);

    //void tick(float dt);
    // implement the "static node()" method manually
    CREATE_FUNC(GameLayer);
};

#endif // __GAMELAYER_H__
